///////////////////////////////////////////////////////////////////////////////
//  
//  Kolonitsky Developers Alicance
//
//
///////////////////////////////////////////////////////////////////////////////


package org.kolonitsky.alexey.graphics
{
	
	public class Color
	{
        public static function parsWebColor(value:String):int
        {
            var str:String = value.replace("#", "0x");
            var result:uint = uint(str);
            return  isNaN(result) ? 0x000000 : result;
        }
		
		/**
		 *  Helper method for conver HSV color space to RGB
		 *  
		 *  @param h
		 *  @param s
		 *  @param v
		 * 
		 *  @return uint integer with RGB color. 
		 */
		public static function hsvToRgb(h:Number, s:Number, v:Number):uint
		{
		    var r:Number, g:Number, b:Number;
		    var i:int;
		    var f:Number, p:Number, q:Number, t:Number;
			var result: uint = 0;
     
		    if (s == 0) 
		    {
		        r = g = b = v;
				result &= Math.round(r * 0xFF) << 16;
				result &= Math.round(g * 0xFF) << 8;
				result &= Math.round(b * 0xFF) << 0;
				result &= 0xFF
				return result; 
		    }
   
		    h /= 60;
		    i = Math.floor(h);
		    f = h - i;
		    p = v *  (1 - s);
		    q = v * (1 - s * f);
		    t = v * (1 - s * (1 - f));
		    
		    switch( i ) 
		    {
		        case 0:  r = v; g = t; b = p; break;
		        case 1:  r = q; g = v; b = p; break;
		        case 2:  r = p; g = v; b = t; break;
		        case 3:  r = p; g = q; b = v; break;
		        case 4:  r = t; g = p; b = v; break;
		        default: r = v; g = p; b = q; break;
		    }
			
			result |= Math.round(r * 0xFF) << 16;
			result |= Math.round(g * 0xFF) << 8; 
			result |= Math.round(b * 0xFF) << 0;
		    return result;
		}

	}
}